package com.powernode.driver.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.powernode.driver.properties.WxMaProperties;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 第三方微信工具类的配置
 */
@Component
public class WxMaConfig {

    @Resource
    private WxMaProperties wxMaProperties;


    /**
     * 创建微信小程序服务 传入 appId和secret
     * @return
     */
    @Bean
    public WxMaService wxMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(wxMaProperties.getAppId());
        config.setSecret(wxMaProperties.getSecret());

        WxMaServiceImpl wxMaService = new WxMaServiceImpl();

        wxMaService.setWxMaConfig(config);

        return wxMaService;
    }
}
